//index.js
//获取应用实例
const DockerSetNet = require('../../setnet/DockerSetNet.js')
const app = getApp()

Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  //事件处理函数
  bindViewTap: function () {
    // wx.navigateTo({
    //   url: '../logs/logs'
    // })
    let setNet = DockerSetNet.create();
    setNet.start('proton2.4', '88831221', (mac) => {
    // setNet.start('去吧皮卡丘', '1127930905ran', (mac) => {
    // setNet.start('xiaomi', '19921127', (mac) => {
    // setNet.start('王梦思的iPhone 王梦思的iPhone 王梦思的iPhone11112333464979989.chhs？？', '199211275319', (mac) => {
      console.log('配网成功...' + mac)
    }, (code, msg) => {
      console.log('配网失败:' + code);
      console.log(msg);
    });
  },
  onReady: function () {
    console.log('去'.charCodeAt());
  let  mac = "AA:BB:CC:DD:EE:0F";
    let lastStr = mac.substr(mac.length - 2, 2);
   let num = parseInt(lastStr, 16);
    num = num - 2;
    console.log(this.test(num));
  },
  test: function(d) { return ("0" + (Number(d).toString(16))).slice(-2).toUpperCase() } ,
  onLoad: function () {
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse) {
      // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo: function (e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  }
})
